Home:ALL Converter>Program Running in Windows\SysWOW64 on user logon instead of Program Files

Program Running in Windows\SysWOW64 on user logon instead of Program Files

Ask Time:2020-11-13T21:42:08         Author:Christian Benner

Json Formatter

I wrote a bootstrapper in C# that launches on user logon and requires access to resources in its install location (Program Files). It cannot locate its resources when launched on user logon. The program launches on user logon because I have used WIX toolkit to create an installer which adds a registry entry to HKMU under 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run'. Here is the WIX wxs part that creates the registry entry:

<DirectoryRef Id="INSTALLFOLDER">
  <!-- Add to system start-up -->
  <Component Id="RegistryEntries" Guid="MYGUIDISHERE">
    <RegistryValue Id="BHWM.rst"
                   Root="HKMU"
                   Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
                   Action="write"
                   Type="string"
                   Name="My Program Name"
                   Value="[INSTALLFOLDER]Bootstrapper.exe"/>
  </Component>
</DirectoryRef>

And INSTALLFOLDER is defined as:

<Directory Id="INSTALLFOLDER" Name="MyCompanyName"\>

The file paths are not absolute, and I wanted to keep them this way. I added a printout to my bootstrapper that prints the absolute path of one of the resources:

Path.GetFullPath("jre\\bin\\server\\jvm.dll")

Which revealed it was looking for the resource under 'C:\Windows\SysWOW64\jre\bin\server\jvm.dll' instead of the desired 'C:\Program Files (x86)\MyCompanyName\jre\bin\server\jvm.dll' (the INSTALLFOLDER), but strangely when printing the location of the application base directory from the bootstrapper using:

AppDomain.CurrentDomain.BaseDirectory

The output is 'C:\Program Files (x86)\MyCompanyName'. I could use this to create an absolute path to my resources but as it is a bootstrapper, it also effects how the program that is being launched by the bootstrapper accesses the same resources. I could pass the application base directory to the program being launched as a parameter but I wanted to avoid this. Is there a way I can run the bootstrapper on user logon to refer to these resources using a reference path? (so not in 'C:\Windows\SysWOW64')

Note: Bootstrapper runs fine when running start menu/desktop shortcuts on running EXE from Program Files directory

Author:Christian Benner,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64821981/program-running-in-windows-syswow64-on-user-logon-instead-of-program-files
yy